package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.BkStats;
import com.stylefeng.guns.modular.system.service.IBkStatsService;

/**
 * 板块强度控制器
 *
 * @author fengshuonan
 * @Date 2018-09-15 20:55:30
 */
@Controller
@RequestMapping("/bkStats")
public class BkStatsController extends BaseController {

    private String PREFIX = "/system/bkStats/";

    @Autowired
    private IBkStatsService bkStatsService;

    /**
     * 跳转到板块强度首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "bkStats.html";
    }

    /**
     * 跳转到添加板块强度
     */
    @RequestMapping("/bkStats_add")
    public String bkStatsAdd() {
        return PREFIX + "bkStats_add.html";
    }

    /**
     * 跳转到修改板块强度
     */
    @RequestMapping("/bkStats_update/{bkStatsId}")
    public String bkStatsUpdate(@PathVariable Integer bkStatsId, Model model) {
        BkStats bkStats = bkStatsService.selectById(bkStatsId);
        model.addAttribute("item",bkStats);
        LogObjectHolder.me().set(bkStats);
        return PREFIX + "bkStats_edit.html";
    }

    /**
     * 获取板块强度列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return bkStatsService.selectList(null);
    }

    /**
     * 新增板块强度
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BkStats bkStats) {
        bkStatsService.insert(bkStats);
        return SUCCESS_TIP;
    }

    /**
     * 删除板块强度
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer bkStatsId) {
        bkStatsService.deleteById(bkStatsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改板块强度
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BkStats bkStats) {
        bkStatsService.updateById(bkStats);
        return SUCCESS_TIP;
    }

    /**
     * 板块强度详情
     */
    @RequestMapping(value = "/detail/{bkStatsId}")
    @ResponseBody
    public Object detail(@PathVariable("bkStatsId") Integer bkStatsId) {
        return bkStatsService.selectById(bkStatsId);
    }
}
